<template>
  <div id="integralRoleExplainTop">
    <h1 class="con-right-title">
      积分规则说明
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <!-- 输入搜索部分 -->
        <el-form-item label="操作人" prop="operator">
          <el-select
            v-model="formInline.operator"
            filterable
            clearable
            placeholder="请输入关键词"
            class="long"
          >
            <el-option
              v-for="item in operatorsList"
              :key="item.userId"
              :label="item.nickname"
              :value="item.userId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select
            v-model="formInline.status"
            filterable
            clearable
            placeholder="请输入关键词"
            class="long"
          >
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getDpNum } from '@/api/system/user'
export default {
  name: 'integralRoleExplainTop',
  msg: '积分规则说明-顶部条件',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          operator: '', // 修改人
          status: '' // 状态
        }
      }
    }
  },
  data() {
    return {
      // 修改人列表
      operatorsList: [{ nickname: '全部', userId: '' }],
      statusList: [{ dictLabel: '全部', dictValue: '' }] // 状态
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  },
  mounted() {
    this.getOperators()
    this.getStatusList()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 获取字典状态 */
    async getStatusList() {
      let data = await sysNormalDisable(
        'Integral_protocol_status',
        'integralRoleStatus'
      )
      this.statusList = this.statusList.concat(data)
    },
    // 获取操作人员
    getOperators() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.operatorsList = this.operatorsList.concat(response)
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>

<style lang="less">
#integralRoleExplain {
}
</style>
